#include <cstring>
#include "gamepiece.h"
#include "global.h"

Gamepiece::Gamepiece(int _x, int _y, int _type, int _color) {
  pos = new Coord(_x, _y);
  type = _type;
  color = _color;
  initialPosition = true;

  switch (_color) {
    case WHITE:
      switch (_type) {
        case PAWN:
          img = new char[sizeof("pieces/pawn_w.png")]();
          strcpy(img, "pieces/pawn_w.png");
          break;
        case ROOK:
          img = new char[sizeof("pieces/rook_w.png")]();
          strcpy(img, "pieces/rook_w.png");
          break;
        case KNIGHT:
          img = new char[sizeof("pieces/knight_w.png")]();
          strcpy(img, "pieces/knight_w.png");
          break;
        case BISHOP:
          img = new char[sizeof("pieces/pawn_w.png")]();
          strcpy(img, "pieces/bishop_w.png");
          break;
        case KING:
          img = new char[sizeof("pieces/king_w.png")]();
          strcpy(img, "pieces/king_w.png");
          break;
        case QUEEN:
          img = new char[sizeof("pieces/queen_w.png")]();
          strcpy(img, "pieces/queen_w.png");
          break;
      }
      break;
    case BLACK:
      switch (_type) {
        case PAWN:
          img = new char[sizeof("pieces/pawn_b.png")]();
          strcpy(img, "pieces/pawn_b.png");
          break;
        case ROOK:
          img = new char[sizeof("pieces/rook_b.png")]();
          strcpy(img, "pieces/rook_b.png");
          break;
        case KNIGHT:
          img = new char[sizeof("pieces/knight_b.png")]();
          strcpy(img, "pieces/knight_b.png");
          break;
        case BISHOP:
          img = new char[sizeof("pieces/pawn_b.png")]();
          strcpy(img, "pieces/bishop_b.png");
          break;
        case KING:
          img = new char[sizeof("pieces/king_b.png")]();
          strcpy(img, "pieces/king_b.png");
          break;
        case QUEEN:
          img = new char[sizeof("pieces/queen_b.png")]();
          strcpy(img, "pieces/queen_b.png");
          break;
      }
      break;
  }
}

Gamepiece::~Gamepiece() {
  delete[] img;
  delete pos;
}
